package com.broada.apm.indicator.api.model;

import java.util.Date;
import org.apache.commons.lang.StringUtils;

public class SearchConditionItem {
	private String field;
	private Object value;
	private Object value_End;
	private Object allValues;
	private boolean isRange;
	private SearchConditionComparator comparator;
	
	public SearchConditionItem(String field, SearchConditionComparator comparator) {
		this.field = field;
		this.comparator = comparator;
	}

	public SearchConditionItem(String field, SearchConditionComparator comparator, Object value) {
		this.field = field;
		this.comparator = comparator;
		this.value = value;
	}

	public SearchConditionItem(String field, SearchConditionComparator comparator, Object value, Object value_End) {
		this.field = field;
		this.comparator = comparator;
		this.value = value;
		this.value_End = value_End;
	}

	public boolean isValid() {
		return ((this.value != null) || (this.value_End != null));
	}

	public boolean isRange() {
		return this.isRange;
	}

	public void setRange(boolean isRange) {
		this.isRange = isRange;
	}

	public String getField() {
		return this.field;
	}

	public void setField(String field) {
		this.field = field;
	}

	public Object getValue() {
		return this.value;
	}

	public Object getOriginalValue() {
		return this.value;
	}

	public void setValue(Object value) {
		if ((value != null) && (value instanceof Date)) {
			this.value = value;
			return;
		}
		if ((value != null) && (value instanceof String))
			value = StringUtils.trim((String) value);
		this.value = value;
	}

	public Object getValue_End() {
		return this.value_End;
	}

	public void setValue_End(Object value_End) {
		if ((value_End != null) && (value_End instanceof String))
			value_End = StringUtils.trim((String) value_End);
		this.value_End = value_End;
	}

	public SearchConditionComparator getComparator() {
		return this.comparator;
	}

	public Object getAllValues() {
		return this.allValues;
	}

	public void setAllValues(Object allValues) {
		this.allValues = allValues;
	}

}